package com.example.activitidemo.controller.common;

import com.example.activitidemo.dto.Event;
import com.example.activitidemo.dto.EventVO;
import com.example.activitidemo.service.event.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: activitidemo
 * @Package: com.example.activitidemo.controller.common
 * @ClassName: CommonDataController
 * @Description:
 * @Author: 张志鹏
 * @CreateDate: 2020-01-08 12:48
 * @UpdateUser: 更新者
 * @UpdateDate: 2020-01-08 12:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@RestController
public class CommonDataController {

    @Autowired
    private EventService eventService;

    @PostMapping("list")
    public List<EventVO> getEventVOList(String assignee) {
        List<Event> list = eventService.findUserTasksAll(assignee);
        List<EventVO> events = new ArrayList<>();
        list.forEach(event -> {
            EventVO eventVO = EventVO.builder()
                    .day(event.getDay())
                    .assignee(event.getAssignee())
                    //当前处理人
                    .assigneeName(event.getAssigneeName())
                    .date(event.getDate())
                    .content(event.getContent())
                    .taskId(event.getTaskId())
                    .id(event.getId()).build();
            events.add(eventVO);
        });
        return events;
    }
}
